package indzcraft.loader;


public class ItemEquiped extends Item {
	
	private Reforge reforge = null;
	public Gem[] gem = new Gem[3];
	Enchant enchant = null;
	private double ep;
	
	public ItemEquiped(){
		super();
	}
	
	public void setReforge(Reforge reforge){
		this.reforge = reforge;
	}
	public void removeReforge(){
		this.reforge = null;
	}
	public Reforge getReforge(){
		if(reforge == null)
			reforge = new Reforge();
		return reforge;
	}
	public void setEnchant(Enchant enchant){
		this.enchant = enchant;
	}
	public Enchant getEnchant(){
		return this.enchant;
	}
	
	public void print(){
		super.print();
		if(reforge != null){
			System.out.println("reforge: " + reforge.getFrom() + " -> " + reforge.getTo());
			System.out.println("reforgeValue: " + getReforgeValue());
		}
		for(int j = 0; j < gem.length;j++){
			if(gem[j] != null)
				System.out.println("gem " + j + ": " + gem[j].getName());
		}
		if(enchant != null)
			System.out.println("enchant: " + enchant.getName());
	}

	public void setGem(int i, Gem gem) {
		this.gem[i] = gem;
	}

	public Gem getGem(int gemSlot) {
		return this.gem[gemSlot];
	}
	
	public int getReforgedCrit() {
		int value = 0;
		if(reforge != null){
			if(reforge.getFrom().equals("Crit Rating")){
				value = getReforgeValue();
			}
			else if(reforge.getTo().equals("Crit Rating")){
				value -= getReforgeValue();
			}
		}
		return super.getCrit()-value;
	}
	public int getReforgedHaste() {
		int value = 0;
		if(reforge != null){
			if(reforge.getFrom().equals("Haste Rating")){
				value = getReforgeValue();
			}
			else if(reforge.getTo().equals("Haste Rating")){
				value -= getReforgeValue();
			}
		}
		return super.getHaste()-value;
	}
	public int getReforgedHit() {
		int value = 0;
		if(reforge != null){
			if(reforge.getFrom().equals("Hit Rating")){
				value = getReforgeValue();
			}
			else if(reforge.getTo().equals("Hit Rating")){
				value -= getReforgeValue();
			}
		}
		return super.getHit()-value;
	}
	public int getReforgedExp() {
		int value = 0;
		if(reforge != null){
			if(reforge.getFrom().equals("Expertise Rating")){
				value = getReforgeValue();
			}
			else if(reforge.getTo().equals("Expertise Rating")){
				value -= getReforgeValue();
			}
		}
		return super.getExp()-value;
	}
	public int getReforgedMastery() {
		int value = 0;
		if(reforge != null){
			if(reforge.getFrom().equals("Mastery Rating")){
				value = getReforgeValue();
			}
			else if(reforge.getTo().equals("Mastery Rating")){
				value -= getReforgeValue();
			}
		}
		return super.getMastery()-value;
	}
	
	public int getReforgeValue(){
		int value = 0;
		if(reforge != null){
			if(reforge.getFrom().equals("Hit Rating")){
				value = (int) Math.floor(super.getHit()*0.4);
			}
			else if(reforge.getFrom().equals("Crit Rating")){
				value = (int) Math.floor(super.getCrit()*0.4);
			}
			else if(reforge.getFrom().equals("Haste Rating")){
				value = (int) Math.floor(super.getHaste()*0.4);
			}
			else if(reforge.getFrom().equals("Mastery Rating")){
				value = (int) Math.floor(super.getMastery()*0.4);
			}
			else if(reforge.getFrom().equals("Expertise Rating")){
				value = (int) Math.floor(super.getExp()*0.4);
			}
		}
		return value;
	}

	public void setEP(double ep) {
		this.ep = ep;
	}
	public double getEP(){
		return this.ep;
	}
}
